<?php

class Admin_IndexController extends Zendvn_Controller_Action {

  protected $_arrParam;

  // Duong dan cua Controller
  protected $_currentController;

  // Duong dan cua Action chinh
  protected $_actionMain;

  public function init() {
    parent::init();
    $this->_arrParam = $this->_request->getParams();

    // Duong dan cua Controller
    $this->_currentController = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller'];

    // Duong dan cua Action chinh
    $this->_actionMain = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller'] . '/index';

    // Truyen ra view
    $this->view->arrParam = $this->_arrParam;
    $this->view->currentController = $this->_currentController;
    $this->view->actionMain = $this->_actionMain;

    $template_path = TEMPLATE_PATH . "/admin/system";
    $this->loadTemplate($template_path, 'template.ini', 'template');
  }

  public function indexAction() {

  }

  public function loginAction() {
    if ($this->_request->isPost()) {
      $auth = new Zendvn_System_Auth();
      if ($auth->login($this->_arrParam)) {
        $info = new Zendvn_System_Info();
        $info->createInfo();
        $this->_redirect('/admin/index/index');
      } else {
        $error[] = $auth->getError();
        $this->view->messageError = $error;
      }
    }
    $this->_helper->layout()->disableLayout();
  }

  public function logoutAction() {
    $auth = new Zendvn_System_Auth();
    $auth->logout();
    $info = new Zendvn_System_Info();
    $info->destroyInfo();
    $this->_redirect('/admin/index/login');
  }
}
